#pragma once

#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

class Solution
{
public:
    bool hasGroupsSizeX(vector<int>& deck)
    {
        int n = deck.size();
        vector<int> v;
        unordered_map<int, int> hash;
        int min = INT_MAX;
        int ret = 0;

        for (int i = 0; i < n; ++i)
        {
            ++hash[deck[i]];
            if (find(v.begin(), v.end(), deck[i]) == v.end())
            {
                v.push_back(deck[i]);
            }
        }

        for (int i = 0; i < v.size(); ++i)
        {
            if (min > hash[v[i]] && hash[v[i]] >= 2)
            {
                min = hash[v[i]];
            }
        }

        for (int i = 0; i < v.size(); ++i)
        {
            if (hash[v[i]] % min != 0)
                return false;
        }
        return true;
    }
};